package com.nf.health.app.activity.home.view;

import android.content.Context;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.home.bean.SatisfactionSurveyQuestionBean;


/**
 * Created by he_pan on 2017/4/12.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author he_pan
 * @Description
 */

public class SingleSelectView extends BaseSelectView {


    protected TextView tvQuestionTitle;
    protected RadioButton rbAnswer1;
    protected RadioButton rbAnswer2;
    protected RadioButton rbAnswer3;
    protected RadioButton rbAnswer4;
    protected RadioButton rbAnswer5;
    protected RadioGroup rgAnswer;

    public SingleSelectView(Context context, SatisfactionSurveyQuestionBean bean, int position) {
        super(context, bean, position);
        initView();
        setUpView();
    }

    protected void initView() {
        View v = inflater.from(context).inflate(R.layout.item_survey_question_single, this);
        tvQuestionTitle = (TextView) v.findViewById(R.id.tv_question_title);
        rbAnswer1 = (RadioButton) findViewById(R.id.rb_answer1);
        rbAnswer2 = (RadioButton) findViewById(R.id.rb_answer2);
        rbAnswer3 = (RadioButton) findViewById(R.id.rb_answer3);
        rbAnswer4 = (RadioButton) findViewById(R.id.rb_answer4);
        rbAnswer5 = (RadioButton) findViewById(R.id.rb_answer5);
        rgAnswer = (RadioGroup) findViewById(R.id.rg_answer);
    }

    protected void setUpView() {
        tvQuestionTitle.setText(position + 1 + ". " + bean.getTitle());
//        rbAnswer1.setText(bean.getOptionList().get(0));
//        rbAnswer2.setText(bean.getOptionList().get(1));
//        rbAnswer3.setText(bean.getOptionList().get(3));
//        rbAnswer4.setText(bean.getOptionList().get(4));
//        rbAnswer5.setText(bean.getOptionList().get(5));
    }

    public String getPosition() {
        return bean.getQnumber();
    }

    public String getSurveyAnswer() {
        String answer = "";
        RadioButton child;
        for (int i = 0; i < rgAnswer.getChildCount(); i++) {
            child = (RadioButton) rgAnswer.getChildAt(i);
            if (child.isChecked()) {
                answer = child.getText().toString().trim();
            }
        }
        return answer;
    }
}
